VERSION 5.00
Begin VB.Form frmReport 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Report"
   ClientHeight    =   4620
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   8370
   Icon            =   "frmReportex.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   4620
   ScaleWidth      =   8370
   Begin VB.CommandButton Command7 
      Caption         =   "EXPENDITURE FOR GINDO"
      Height          =   495
      Left            =   5400
      TabIndex        =   15
      Top             =   2760
      Width           =   2655
   End
   Begin VB.PictureBox Picture1 
      BorderStyle     =   0  'None
      Height          =   855
      Left            =   120
      Picture         =   "frmReportex.frx":1CCA
      ScaleHeight     =   855
      ScaleWidth      =   855
      TabIndex        =   14
      Top             =   120
      Width           =   855
   End
   Begin VB.CommandButton Command6 
      Caption         =   "Close"
      Height          =   495
      Left            =   5400
      TabIndex        =   12
      Top             =   3960
      Width           =   2535
   End
   Begin VB.Frame Frame1 
      Height          =   3735
      Left            =   1200
      TabIndex        =   1
      Top             =   120
      Width           =   7095
      Begin VB.ComboBox cboOffice2 
         Enabled         =   0   'False
         Height          =   315
         Left            =   1320
         TabIndex        =   27
         Top             =   3240
         Width           =   1335
      End
      Begin VB.ComboBox cboFinancial 
         Enabled         =   0   'False
         Height          =   315
         Left            =   1320
         TabIndex        =   25
         Top             =   2880
         Width           =   2535
      End
      Begin VB.ComboBox cboTY 
         Enabled         =   0   'False
         Height          =   315
         Left            =   2760
         TabIndex        =   23
         Top             =   2520
         Width           =   1095
      End
      Begin VB.CheckBox chkAdvanceDate 
         Caption         =   "Expenditure report for more than one month"
         ForeColor       =   &H000000FF&
         Height          =   375
         Left            =   1320
         TabIndex        =   22
         Top             =   1680
         Width           =   2775
      End
      Begin VB.ComboBox cboTM 
         Enabled         =   0   'False
         Height          =   315
         Left            =   1320
         TabIndex        =   20
         Top             =   2520
         Width           =   855
      End
      Begin VB.ComboBox cboFY 
         Enabled         =   0   'False
         Height          =   315
         Left            =   2760
         TabIndex        =   17
         Top             =   2160
         Width           =   1095
      End
      Begin VB.ComboBox cboFM 
         Enabled         =   0   'False
         Height          =   315
         Left            =   1320
         TabIndex        =   16
         Top             =   2160
         Width           =   855
      End
      Begin VB.CommandButton cmdGindo 
         Caption         =   "CASH FLOW FOR GINDO"
         Height          =   375
         Left            =   4200
         TabIndex        =   13
         Top             =   720
         Width           =   2655
      End
      Begin VB.CommandButton Command1 
         Caption         =   "BUDGETSUMMARY BY OFFICE"
         Height          =   375
         Left            =   4200
         TabIndex        =   8
         Top             =   1200
         Width           =   2655
      End
      Begin VB.CommandButton Command2 
         Caption         =   "BUDGET SUMMARY FOR GINDO"
         Height          =   375
         Left            =   4200
         TabIndex        =   7
         Top             =   1680
         Width           =   2655
      End
      Begin VB.CommandButton Command3 
         Caption         =   "CASH FLOW BY OFFICE"
         Height          =   375
         Left            =   4200
         TabIndex        =   6
         Top             =   240
         Width           =   2655
      End
      Begin VB.CommandButton Command4 
         Caption         =   "EXPENDITURE BY OFFICE"
         Height          =   375
         Left            =   4200
         TabIndex        =   5
         Top             =   2160
         Width           =   2655
      End
      Begin VB.ComboBox cboOffice 
         Height          =   315
         Left            =   1320
         TabIndex        =   4
         Top             =   480
         Width           =   1335
      End
      Begin VB.ComboBox cboMonth 
         Height          =   315
         Left            =   1320
         TabIndex        =   3
         Top             =   840
         Width           =   1335
      End
      Begin VB.ComboBox cboYear 
         Height          =   315
         Left            =   1320
         TabIndex        =   2
         Top             =   1200
         Width           =   1335
      End
      Begin VB.Label Label9 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "Office"
         Height          =   195
         Left            =   795
         TabIndex        =   28
         Top             =   3240
         Width           =   420
      End
      Begin VB.Label Label8 
         Alignment       =   1  'Right Justify
         Caption         =   "Financial"
         Height          =   255
         Left            =   120
         TabIndex        =   26
         Top             =   3000
         Width           =   1095
      End
      Begin VB.Label Label7 
         Alignment       =   1  'Right Justify
         Caption         =   "Year"
         Height          =   255
         Left            =   2280
         TabIndex        =   24
         Top             =   2520
         Width           =   375
      End
      Begin VB.Label Label6 
         Alignment       =   1  'Right Justify
         Caption         =   "To Month"
         Height          =   255
         Left            =   240
         TabIndex        =   21
         Top             =   2640
         Width           =   975
      End
      Begin VB.Label Label5 
         Alignment       =   1  'Right Justify
         Caption         =   "Year"
         Height          =   255
         Left            =   2040
         TabIndex        =   19
         Top             =   2160
         Width           =   615
      End
      Begin VB.Label Label4 
         Alignment       =   1  'Right Justify
         Caption         =   "From Month"
         Height          =   255
         Left            =   240
         TabIndex        =   18
         Top             =   2160
         Width           =   975
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "Office"
         Height          =   195
         Left            =   795
         TabIndex        =   11
         Top             =   480
         Width           =   420
      End
      Begin VB.Label Label2 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "Month"
         Height          =   195
         Left            =   765
         TabIndex        =   10
         Top             =   840
         Width           =   450
      End
      Begin VB.Label Label3 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "Year"
         Height          =   195
         Left            =   885
         TabIndex        =   9
         Top             =   1200
         Width           =   330
      End
   End
   Begin VB.CommandButton Command5 
      Caption         =   "&Close"
      Height          =   615
      Left            =   5520
      TabIndex        =   0
      Top             =   8160
      Width           =   3855
   End
End
Attribute VB_Name = "frmReport"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cboFM_LostFocus()
tem = SetFinancial(cboFM, Right(cboFY.Text, 2), cboTM.Text, Right(cboTY.Text, 2))
End Sub

Private Sub cboFY_LostFocus()
tem = SetFinancial(cboFM, Right(cboFY.Text, 2), cboTM.Text, Right(cboTY.Text, 2))
End Sub

Private Sub cboTM_Click()
If Val(cboTY.Text) = Val(cboFY.Text) Then
    If Val(cboTM.Text) < Val(cboFM.Text) Then
        MsgBox "The TO MONTH must be greater then FROM MONTH", vbCritical + vbOKOnly, "Checking"
        Exit Sub
    End If
End If

End Sub

 

Private Sub cboTM_LostFocus()
tem = SetFinancial(cboFM, Right(cboFY.Text, 2), cboTM.Text, Right(cboTY.Text, 2))
End Sub

Private Sub cboTY_Click()
If Val(cboTY.Text) < Val(cboFY.Text) Then
    MsgBox "The TO YEAR must be greater then FROM YEAR", vbCritical + vbOKOnly, "Checking"
End If
End Sub

Private Sub cboTY_LostFocus()
Dim tem As String
tem = SetFinancial(cboFM, Right(cboFY.Text, 2), cboTM.Text, Right(cboTY.Text, 2))
If tem <> "" Then
    MsgBox tem, vbInformation + vbOKOnly, "Checking"
End If
End Sub

Private Sub chkAdvanceDate_KeyUp(KeyCode As Integer, Shift As Integer)
If chkAdvanceDate.Value = 0 Then
    cboFM.Enabled = True
    cboTM.Enabled = True
    cboFY.Enabled = True
    cboTY.Enabled = True
    cboOffice2.Enabled = True
    cboOffice.Enabled = False
    cboFinancial.Enabled = True
Else
    cboFM.Enabled = False
    cboTM.Enabled = False
    cboFY.Enabled = False
    cboTY.Enabled = False
    cboOffice2.Enabled = False
    cboFinancial.Enabled = False
    cboOffice.Enabled = True
End If
End Sub

Private Sub chkAdvanceDate_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
If chkAdvanceDate.Value = 1 Then
    cboFM.Enabled = True
    cboTM.Enabled = True
    cboFY.Enabled = True
    cboTY.Enabled = True
    cboOffice2.Enabled = True
    cboFinancial.Enabled = True
    cboOffice.Enabled = False
Else
    cboFM.Enabled = False
    cboTM.Enabled = False
    cboFY.Enabled = False
    cboTY.Enabled = False
    cboOffice2.Enabled = False
    cboFinancial.Enabled = False
    cboOffice.Enabled = True
End If
End Sub

Private Sub cmdGindo_Click()
'On Error Resume Next
Dim previousMMYY As String
Dim mm, yy As String
mm = cboMonth.Text
yy = Right(cboYear.Text, 2)
If Val(mm) = 1 Then
    previousMMYY = "120" & Val(yy) - 1
ElseIf Val(mm) - 1 < 10 Then
    previousMMYY = "0" & Val(mm) - 1 & yy
ElseIf Val(mm) - 1 >= 10 Then
    previousMMYY = Val(mm) - 1 & yy
End If
DetectExcel
If Not isExistBalance(Left(previousMMYY, 2), Right(previousMMYY, 2), Right(cboOffice.Text, 3)) Then
    If MsgBox("The balance of previous month does not exist. Do you want to update the balance manually?(Y/N)", vbQuestion + vbYesNo + vbDefaultButton2, "Update Balance?") = vbNo Then
        Exit Sub
    Else
        frmBalance.Show
        frmBalance.cboBMonth.Text = Left(previousMMYY, 2)
        frmBalance.cboBYear.Text = "20" & Right(previousMMYY, 2)
        Exit Sub
    End If
End If

Call funCASHFLOWREPORT(cboMonth.Text, Right(cboYear.Text, 2), 1)
End Sub

 

Private Sub Command1_Click()
Call funBUDGETSUMMARY(Right(cboYear.Text, 2))
End Sub

Private Sub Command2_Click()
Call fcnGINDOBUDGETSUMMARY(Right(cboYear.Text, 2))
End Sub

Private Sub Command3_Click()
'On Error Resume Next
Dim previousMMYY As String
Dim mm, yy As String
mm = cboMonth.Text
yy = Right(cboYear.Text, 2)
If Val(mm) = 1 Then
    previousMMYY = "120" & Val(yy) - 1
ElseIf Val(mm) - 1 < 10 Then
    previousMMYY = "0" & Val(mm) - 1 & yy
ElseIf Val(mm) - 1 >= 10 Then
    previousMMYY = Val(mm) - 1 & yy
End If
DetectExcel
If Not isExistBalance(Left(previousMMYY, 2), Right(previousMMYY, 2), Right(cboOffice.Text, 3)) Then
    If MsgBox("The balance of previous month does not exist. Do you want to update the balance manually?(Y/N)", vbQuestion + vbYesNo + vbDefaultButton2, "Update Balance?") = vbNo Then
        Exit Sub
    Else
        frmBalance.Show
        frmBalance.cboBMonth.Text = Left(previousMMYY, 2)
        frmBalance.cboBYear.Text = "20" & Right(previousMMYY, 2)
        Exit Sub
    End If
End If
TotalExpenditureInCashFlow = 0
Call funCASHFLOWREPORT(cboMonth.Text, Right(cboYear.Text, 2), 0)
End Sub

Private Sub Command4_Click()
'On Error Resume Next
 
    Dim ExcelWasNotRunning As Boolean   ' Flag for final release.
Dim previousYear As String
previousYear = Val(Right(cboYear.Text, 2)) - 1
If Len(previousYear) < 2 Then
    previousYear = "0" & previousYear
End If
TotalExpenditureCheck = 0
isExportExpenditureForGindo = False
isNoCloseExcel = False





DetectExcel
If chkAdvanceDate.Value = 1 Then
    'If Val(cboTM.Text) < Val(cboFM.Text) Then
         'MsgBox "The TO MONTH must be greater then FROM MONTH", vbCritical + vbOKOnly, "Checking"
        ' Exit Sub
    'End If
    isFillCheck = 1
    isCreateNewExcel = True
    Call funExpenditureREPORT(cboFinancial.Text, "", cboFM.Text, Right(cboFY.Text, 2), cboTM.Text, Right(cboTY.Text, 2), cboOffice2.Text, False, True)

Else
        Select Case Val(cboMonth.Text)
        
        Case 1, 2, 3
            isFillCheck = 1
            isCreateNewExcel = True
            'Call funExpenditureREPORT(previousYear & "S", cboMonth.Text, Right(cboYear.Text, 2), cboOffice.Text)
            Call funExpenditureREPORT(Right(cboYear.Text, 2) & "F", previousYear & "S", cboMonth.Text, Right(cboYear.Text, 2), "", "", cboOffice.Text, False, False)
        Case 4, 5, 6
            isFillCheck = 2
            isCreateNewExcel = True
            Call funExpenditureREPORT(Right(cboYear.Text, 2) & "F", "", cboMonth.Text, Right(cboYear.Text, 2), "", "", cboOffice.Text, False, False)
        Case 7, 8, 9
            isFillCheck = 1
            isCreateNewExcel = True
            'Call funExpenditureREPORT(Right(cboYear.Text, 2) & "F", cboMonth.Text, Right(cboYear.Text, 2), cboOffice.Text)
            Call funExpenditureREPORT(Right(cboYear.Text, 2) & "S", Right(cboYear.Text, 2) & "F", cboMonth.Text, Right(cboYear.Text, 2), "", "", cboOffice.Text, False, False)
        Case 10, 11, 12
            isFillCheck = 2
            isCreateNewExcel = True
            Call funExpenditureREPORT(Right(cboYear.Text, 2) & "S", "", cboMonth.Text, Right(cboYear.Text, 2), "", "", cboOffice.Text, False, False)
        End Select
End If
End Sub

Private Sub Command5_Click()
Unload Me
End Sub

Private Sub Command6_Click()
Unload Me
End Sub



Private Sub Command7_Click()
'On Error Resume Next
Dim previousYear As String
previousYear = Val(Right(cboYear.Text, 2)) - 1
If Len(previousYear) < 2 Then
    previousYear = "0" & previousYear
End If
DetectExcel

TotalExpenditureCheck = 0
isExportExpenditureForGindo = True

If chkAdvanceDate.Value = 1 Then
'    If Val(cboTM.Text) < Val(cboFM.Text) Then
'         MsgBox "The TO MONTH must be greater then FROM MONTH", vbCritical + vbOKOnly, "Checking"
'         Exit Sub
'    End If
    isFillCheck = 1
    isCreateNewExcel = True
     Call funExpenditureREPORT(cboFinancial.Text, "", cboFM.Text, Right(cboFY.Text, 2), cboTM.Text, Right(cboTY.Text, 2), cboOffice2.Text, True, True)
    'Call funExpenditureREPORT(Right(cboFY.Text, 2) & "S", Right(cboFY.Text, 2) & "F", cboFM.Text, Right(cboFY.Text, 2), cboTM.Text, Right(cboFY.Text, 2), cboOffice.Text, True, True)

Else
        
        Select Case Val(cboMonth.Text)
        
        Case 1, 2, 3
            isFillCheck = 1
            isCreateNewExcel = True
            'Call funExpenditureREPORT(previousYear & "S", cboMonth.Text, Right(cboYear.Text, 2), cboOffice.Text)
            Call funExpenditureREPORT(Right(cboYear.Text, 2) & "F", previousYear & "S", cboMonth.Text, Right(cboYear.Text, 2), "", "", cboOffice.Text, True, False)
        Case 4, 5, 6
            isFillCheck = 2
            isCreateNewExcel = True
            Call funExpenditureREPORT(Right(cboYear.Text, 2) & "F", "", cboMonth.Text, Right(cboYear.Text, 2), "", "", cboOffice.Text, True, False)
        Case 7, 8, 9
            isFillCheck = 1
            isCreateNewExcel = True
            'Call funExpenditureREPORT(Right(cboYear.Text, 2) & "F", cboMonth.Text, Right(cboYear.Text, 2), cboOffice.Text)
            Call funExpenditureREPORT(Right(cboYear.Text, 2) & "S", Right(cboYear.Text, 2) & "F", cboMonth.Text, Right(cboYear.Text, 2), "", "", cboOffice.Text, True, False)
        Case 10, 11, 12
            isFillCheck = 2
            isCreateNewExcel = True
            Call funExpenditureREPORT(Right(cboYear.Text, 2) & "S", "", cboMonth.Text, Right(cboYear.Text, 2), "", "", cboOffice.Text, True, False)
        End Select
End If
End Sub

Private Function SetFinancial(fromMonth As Integer, fromYear As Integer, toMonth As Integer, toYear As Integer) As String
Dim i As Integer
cboFinancial.Clear
If fromYear > toYear Then
    SetFinancial = "'From year' can not be greater then 'to year'"
    Exit Function
ElseIf fromYear = toYear Then
    If fromMonth > toMonth Then
        SetFinancial = "'From month' can not be greater then 'to month'"
        Exit Function
    End If
End If
cboFinancial.AddItem "ALL"
If fromMonth >= 1 And fromMonth <= 3 Then
    If fromYear - 1 < 10 Then
        cboFinancial.AddItem "0" & fromYear - 1 & "S"
    Else
        cboFinancial.AddItem fromYear - 1 & "S"
    End If
End If
For i = fromYear To toYear Step 1
    If i < 10 Then
        cboFinancial.AddItem "0" & i & "F"
        cboFinancial.AddItem "0" & i & "S"
    Else
        cboFinancial.AddItem i & "F"
        cboFinancial.AddItem i & "S"
    End If
    
Next i
SetFinancial = ""
End Function

Private Sub Form_Load()
DetectExcel
Me.Top = Screen.Height / 2 - (Me.Height / 1.5)
    Me.Left = Screen.Width / 2 - (Me.Width / 2)
Call KetNoi

For i = 1 To 9
    cboMonth.AddItem "0" & i
Next i
For i = 10 To 12
    cboMonth.AddItem i
Next i
If Month(Now()) < 10 Then
    If Month(Now()) = 1 Then
        cboMonth.Text = "0" & Month(Now())
    Else
        cboMonth.Text = "0" & Month(Now()) - 1
    End If
Else
    cboMonth.Text = Month(Now()) - 1
End If
For i = 7 To Val(Right(Year(Now()), 2))
    cboYear.AddItem "200" & i
Next i
cboYear.Text = Year(Now())

For i = 1 To 9
        cboFM.AddItem "0" & i
        cboTM.AddItem "0" & i
        If Val(i) = Month(Now()) Then
            cboFM.ListIndex = i - 1
            cboTM.ListIndex = i - 1
        End If
    Next
    For i = 10 To 12
        cboFM.AddItem i
        cboTM.AddItem i
    Next
    For i = 2008 To Year(Now()) + 1
        cboFY.AddItem i
        cboTY.AddItem i
    Next
    cboFY.Text = Year(Now())
    cboTY.Text = Year(Now())
Select Case permit
    Case "A", "B", "G"
        cboOffice.Enabled = True
        'cboOffice2.Enabled = True
        chkAdvanceDate.Enabled = True
        
            cboOffice.AddItem "GHAN"
            cboOffice.AddItem "GSGN"
            'cboOffice.AddItem "GDAD"
            cboOffice.AddItem "GPNH"
            cboOffice.AddItem "GVTE"
            cboOffice.ListIndex = 1
            
            cmdGindo.Enabled = True
            
            cboOffice2.AddItem "GHAN"
            cboOffice2.AddItem "GSGN"
            'cboOffice2.AddItem "GDAD"
            cboOffice2.AddItem "GPNH"
            cboOffice2.AddItem "GVTE"
            cboOffice2.ListIndex = 1
            
            
            
       

    Case Else
        cboOffice.AddItem "G" & stroffice
        cboOffice.ListIndex = 0
        cboOffice.Enabled = False
        cboOffice2.Enabled = False
        chkAdvanceDate.Enabled = False
         
            
End Select
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
ApExcel.Quit
End Sub

Private Sub Form_Terminate()
On Error Resume Next
ApExcel.Quit
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
ApExcel.Quit
End Sub
